#[cfg(test)]
mod tests {
    #[test]
    fn range() {
        for number in (1..4).rev() {
            println!("{}!", number);
        }
        for number in 1..4 {
            println!("{}!!", number);
        }
    }

    #[test]
    fn loop_() {
        let mut counter = 0;
        let result = loop {
            counter += 1;
            if counter == 10 {
                break counter * 2;
            }
        };
        println!("{} {}", counter, result)
    }

    #[test]
    fn while_() {
        let mut number = 3;
        while number != 0 {
            println!("{}!", number);
            number = number - 1;
        }
        println!("{}", number)
    }

    #[test]
    fn iter_() {
        let a = [10, 20, 30, 40, 50];
        for element in a.iter() {
            // *element += 1;
            print!("{},", element);
        }
        println!();
        println!("arr:{:?}", a);
        //修改原數組
        let mut arr = [10, 20, 30, 40, 50];
        for element in arr.iter_mut() {
            *element += 1;
            print!("{},", element);
        }
        println!();
        println!("arr:{:?}", arr);

        let normal = [11, 21, 31, 41, 51];
        println!("{:?}", normal.get(1));
        println!("{:?}", normal.get(6) == None);
    }

    #[test]
    fn for_() {
        let arr = [10, 20, 30, 40, 50];
        //     for item in collection	for item in IntoIterator::into_iter(collection)	转移所有权
        //     for item in &collection	for item in collection.iter()	不可变借用
        //     for item in &mut collection	for item in collection.iter_mut()	可变借用
        for (i, v) in arr.iter().enumerate() {
            print!("{}-->{}; ", i, v)
        }
        println!();
        let mut arr_mut = [10, 20, 30, 40, 50];
        for v in arr_mut.iter_mut() {
            // 连续 迭代+不可读 性能更高
            *v += 1;
            print!("{} ", v)
        }
        println!();
        println!("arr_mut:{:?}", arr_mut);
        for v in 0..arr_mut.len() {
            // 边界检查+脏读(可变)
            arr_mut[v] += 1;
            print!("{} ", arr_mut[v])
        }
        println!();
        println!("arr_mut:{:?}", arr_mut);
    }
}
